import math
import sys
import os
import struct
import matplotlib.pyplot as plt
list = [261, 293, 329, 349, 392, 440, 493, 
        523, 587, 659, 698, 783, 880, 987, 
        1046, 1174, 1318, 1396, 1567, 1760, 1975, 2093]

for freq in list:
    time = 200 # 时长
    sample = 22050 # 采样率
    widths = 8 # 声音位数
    wave = []
    f = open(f"ac3/{sample}_sin_{time}ms_{freq}hz.ac3", "wb")
    data = []
    for i in range(int(sample * time / 1000)):
        a = (math.sin(2 * math.pi * freq * i / sample + math.pi * 3 / 2) + 1) / 2 * (math.pow(2, widths)-1)
        wave.append(int(a))
        f.write(struct.pack('B', int(a)))
    f.close 
    print(f"{sample}_sin_{time}ms_{freq}hz.ac3 生成完毕")

